import "LotroLCD.LotroLCD.UI";

LotroLCDEditPopupWindow = class(LotroLCDWindow);
function LotroLCDEditPopupWindow:Constructor(parent, settings, plugin)
	Turbine.UI.Lotro.Window.Constructor(self);
	
	-- Keep track of parent and base plugin object
	self.parent = parent;
	self.plugin = plugin;
	
	-- Associate settings
	self.settings = settings;
	
	
	self:SetVisible(false);
	self:SetOpacity(self.settings.opacity);
	self:SetSize(300, 70);
	self:SetText("Edit");
	self:SetZOrder(3);
	
	self.textbox = Turbine.UI.Lotro.TextBox();
	self.textbox:SetParent(self);
	self.textbox:SetPosition( 15, 50 );
	self.textbox:SetSize( 185, 20 );
	self.textbox:SetFontStyle(Turbine.UI.FontStyle.Outline);
	self.textbox:SetFont(Turbine.UI.Lotro.Font.Verdana14);
	self.textbox:SetTextAlignment(Turbine.UI.ContentAlignment.MiddleLeft);
	self.textbox:SetMultiline( false );
	
	self.commitButton = Turbine.UI.Lotro.Button();
	self.commitButton:SetParent(self);
	self.commitButton:SetPosition( 215, 50);
	self.commitButton:SetSize(80, 20);
	self.commitButton:SetText("Update");
end

function LotroLCDEditPopupWindow:Activate(settings, value, control)
	self.textbox:SetText(value);
	
	-- Manually center the edit popup window
	local displayWidth, displayHeight = Turbine.UI.Display.GetSize();
    local windowWidth, windowHeight = self:GetSize();
    self:SetPosition( ( displayWidth - windowWidth ) / 2,  ( displayHeight - windowHeight ) / 2 );
	
	-- Update Opacity setting to match parent
	if settings.opacity then
		self:SetOpacity(settings.opacity);
	end
	
	self.commitButton.MouseClick = function( sender, args )
		value = self.textbox:GetText();
		control:SetText(value);
		self.parent.parent.settings.windowTitle = value;
		--Turbine.Shell.WriteLine(self.parent.parent.settings.windowTitle);
		self.parent:SaveSettings();
		self:Deactivate();
	end
	
	self:SetVisible(true);
end

function LotroLCDEditPopupWindow:Deactivate( )
	self:SetVisible(false);
end
